package cn.juc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程等待高级应用 王者荣耀
 */
public class CountLatchTest {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(10);
          CountDownLatch latch=new CountDownLatch(10);
        String[] all = new String[10];
        Random random = new Random();
        for (int k = 0; k < 10; k++) {
              int x=k;
            pool.submit(() -> {
                for (int i = 0; i <= 100; i++) {
                    int j = i;
                    all[x] = j + "%";
                    try {
                        Thread.sleep(random.nextInt(100));
                       // latch.countDown();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.print("\r"+Arrays.toString(all));
                }
                latch.countDown();
            });
        }
        latch.await();
        System.out.println("\n游戏开始");
        pool.shutdown();
    }
}
